<?php
class UCCASS_AllSurveys extends UCCASS_Main
{
       
    /**************
    * CONSTRUCTOR *
    **************/
    function UCCASS_AllSurveys()
    { $this->load_configuration(); }
    
    function categorias(){
        /*$sql = "SELECT cid, category 
                FROM {$this->CONF['db_tbl_prefix']}category
                WHERE active=1";*/
        $sql = "SELECT c.cid, c.category
                FROM {$this->CONF['db_tbl_prefix']}category c, {$this->CONF['db_tbl_prefix']}surveys s
                WHERE s.sid != 0 and c.exit = 'pub' and c.active = 1  and  s.category = c.cid group by c.cid";
        /*echo $sql;
        exit;*/
		$rs = $this->db->Execute($sql);
		
	    $x=0;
	   	while($r = $rs->FetchRow($rs)){
    		$resuls[$x]["cid"]= $r["cid"];
    		$resuls[$x]["category"]= $r["category"];
    		$x++;
    	}
    	
    	$this->smarty->assign('mostrar','categ');
    	$this->smarty->assign('url',$this->CONF["html"]);	
		$this->smarty->assign('aactivas',$resuls);
      

        return $this->smarty->fetch($this->template.'/mostrarcategorias.tpl');
    	
    }
    
    function todasdecategoria($cid){
            
        /*$sql = "SELECT sid, name 
                FROM {$this->CONF['db_tbl_prefix']}surveys
                WHERE category = $cid and sid > 0 and active = 1";*/
       

        $sql = "SELECT sid, qid, question 
			    FROM {$this->CONF['db_tbl_prefix']}questions 
			    WHERE qid IN (
                              SELECT min(qid) FROM {$this->CONF['db_tbl_prefix']}questions WHERE sid IN ( 
                                                                                                         SELECT sid FROM {$this->CONF['db_tbl_prefix']}surveys WHERE category = $cid AND sid > 0 AND active = 1
                                                                                                         ) 
                              GROUP BY sid
                             )"; 
		
			    
        $rs = $this->db->Execute($sql);
   
	  	$x=0;
				
		while($r = $rs->FetchRow($rs)){
		
    		$resuls[$x]["sid"]= $r["sid"];
    		$resuls[$x]["name"]= $r["question"];
    		
			$x++;
    	}
        	
    	$this->smarty->assign('mostrar','porcat');
    	$this->smarty->assign('url',$this->CONF["html"]);	
		$this->smarty->assign('encues',$resuls);
       

        return $this->smarty->fetch($this->template.'/mostrarcategorias.tpl');
    }
    
}
 
?>